package com.mlf.builder;

import com.mlf.builder.car.Car;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SpringELDemo {
    public static void main(String[] args) {

        ExpressionParser parser = new SpelExpressionParser();
        StandardEvaluationContext context = new StandardEvaluationContext();
        Car car = new Car();
        car.setCarName("宝马123");
        car.setLength("220");

        String rule = "length() <= 2";
        Boolean valid = parser.parseExpression(rule)
                .getValue(context, car.getCarName(), Boolean.class);
        if (!valid) {
            throw new RuntimeException("属性校验失败");
        }


    }
}
